﻿namespace ExamV5.WorkExam
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class AddWorkExamReule : Page
    {
        protected Button butAdd;
        protected Button butDefault;
        protected GridView DataGridInfo;
        protected HtmlForm Form1;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        private int int_0 = 0;
        private PublicFun publicFun_0 = new PublicFun();
        protected ScriptManager SM;
        protected TextBox txtGradeDMax;
        protected TextBox txtGradeDMin;
        protected TextBox txtResultName;
        protected UpdatePanel UPPart;

        protected void butAdd_Click(object sender, EventArgs e)
        {
            this.publicFun_0.ExecuteSql(string.Concat(new object[] { "insert into WorkGradeReule(ReuleName,MinValue,MaxValue,PaperID) values('", this.publicFun_0.CheckString(this.txtResultName.Text), "','", this.txtGradeDMin.Text.Trim(), "','", this.txtGradeDMax.Text.Trim(), "','", this.int_0, "')" }));
            this.method_0();
            this.txtGradeDMin.Text = "";
            this.txtGradeDMax.Text = "";
            this.txtResultName.Text = "";
        }

        protected void butDefault_Click(object sender, EventArgs e)
        {
            if (!(this.publicFun_0.GetValues("select ID from WorkGradeReule where PaperID=" + this.int_0, "ID") == ""))
            {
                string str = base.Request.Url.ToString();
                str = str.Substring(0, str.LastIndexOf('/') + 1);
                base.Response.Redirect(str + "AddJoinMan.aspx?ID=" + this.int_0);
            }
            else
            {
                ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BAPower", "alert('请输入测评结果标准值！')", true);
            }
        }

        protected void DataGridInfo_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            this.DataGridInfo.EditIndex = -1;
            this.method_0();
        }

        protected void DataGridInfo_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.DataItemIndex != -1)
            {
                e.Row.Attributes.Add("onmouseover", "this.bgColor='#F6F5F5'");
                if ((e.Row.DataItemIndex % 2) != 0)
                {
                    e.Row.Attributes.Add("bgcolor", "#FFFFFF");
                    e.Row.Attributes.Add("onmouseout", "this.bgColor=document.getElementById('DataGridInfo').getAttribute('oldValue')");
                }
                else
                {
                    e.Row.Attributes.Add("bgcolor", "#FFFFFF");
                    e.Row.Attributes.Add("onmouseout", "this.bgColor=document.getElementById('DataGridInfo').getAttribute('singleValue')");
                }
            }
            else
            {
                this.DataGridInfo.Attributes.Add("oldValue", "#FFFFFF");
                this.DataGridInfo.Attributes.Add("singleValue", "#FFFFFF");
            }
            if ((e.Row.RowIndex != -1) && ((e.Row.RowState == DataControlRowState.Edit) || (e.Row.RowState == (DataControlRowState.Edit | DataControlRowState.Alternate))))
            {
                TextBox box = (TextBox) e.Row.Cells[1].Controls[0];
                box.Width = 250;
                box.CssClass = "text";
                box.Height = 0x17;
            }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                LinkButton button = (LinkButton) e.Row.Cells[3].FindControl("LBDel");
                button.Attributes.Add("onclick", "javascript:{if(confirm('确定删除测评结果信息[" + e.Row.Cells[1].Text + "]吗？')==false) return false;}");
            }
        }

        protected void DataGridInfo_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string str = this.DataGridInfo.DataKeys[e.RowIndex]["ID"].ToString();
            this.publicFun_0.ExecuteSql(string.Concat(new object[] { "Delete from WorkGradeReule  where PaperID=", this.int_0, " and ID=", str }));
            this.method_0();
        }

        protected void DataGridInfo_RowEditing(object sender, GridViewEditEventArgs e)
        {
            this.DataGridInfo.EditIndex = e.NewEditIndex;
            this.method_0();
        }

        protected void DataGridInfo_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            try
            {
                string str = this.DataGridInfo.DataKeys[e.RowIndex]["ID"].ToString();
                string text = ((TextBox) this.DataGridInfo.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
                string str3 = ((TextBox) this.DataGridInfo.Rows[e.RowIndex].Cells[0].FindControl("txtMinValue")).Text;
                string str4 = ((TextBox) this.DataGridInfo.Rows[e.RowIndex].Cells[0].FindControl("txtMaxValue")).Text;
                this.publicFun_0.ExecuteSql(string.Concat(new object[] { "update WorkGradeReule set ReuleName='", this.publicFun_0.CheckString(text), "',MinValue='", str3, "',MaxValue='", str4, "' where PaperID=", this.int_0, " and ID=", str }));
                this.DataGridInfo.EditIndex = -1;
                this.method_0();
            }
            catch
            {
            }
        }

        private void method_0()
        {
            SqlConnection selectConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            SqlDataAdapter adapter = new SqlDataAdapter("select * from WorkGradeReule where PaperID=" + this.int_0 + " order by ID desc", selectConnection);
            DataSet dataSet = new DataSet();
            adapter.Fill(dataSet, "GradeReule");
            this.DataGridInfo.DataSource = dataSet.Tables["GradeReule"].DefaultView;
            this.DataGridInfo.DataBind();
            adapter.Dispose();
            dataSet.Dispose();
            selectConnection.Dispose();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            if ((this.httpCookie_0 != null) ? !(this.httpCookie_0.Value == "") : false)
            {
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                this.int_0 = Convert.ToInt32(base.Request["ID"].ToString());
                if (!base.IsPostBack)
                {
                    if (!(this.publicFun_0.ReturnPaperData() != "Yes"))
                    {
                        this.butDefault.Attributes.Add("onclick", "javascript:{if(confirm('确定规则定义完毕，进行下一步设置？')==false) return false;}");
                        this.method_0();
                        this.Page.Title = ConfigurationManager.ConnectionStrings["ProTitle"].ConnectionString;
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheck", "alert('此版本暂未授权,请拔打(0)13870606104手机号进行授权！')", true);
                    }
                }
            }
            else
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
        }
    }
}

